package service

import (
	"xadmin/backend/internal/model"
	"xadmin/backend/internal/repository"
)

type UserService struct {
	userRepo *repository.UserRepository
}

func NewUserService(userRepo *repository.UserRepository) *UserService {
	return &UserService{userRepo: userRepo}
}

func (s *UserService) List(page, pageSize int) ([]model.User, error) {
	return s.userRepo.List(page, pageSize)
}

func (s *UserService) Get(id uint) (*model.User, error) {
	return s.userRepo.FindByID(id)
}

func (s *UserService) Update(id uint, username string, roleID uint) error {
	user, err := s.userRepo.FindByID(id)
	if err != nil {
		return err
	}

	user.Username = username
	user.RoleID = roleID

	return s.userRepo.Update(user)
}

func (s *UserService) Delete(id uint) error {
	return s.userRepo.Delete(id)
}
